using System;
using System.Data;
using WP.DB;
using WP.MF.DataEntity;
using WP.Commons;

namespace WP.MF.DataAccess
{
    public class MPrinterDAL : IDataAccess
    {
        public MPrinterDAL()
        { 
        }
        #region Select List
        public string SQLList(int iParameter)
        {
            string strSQL = @"SELECT RecID, UserName, ReportType,CopyType,PrinterName From mPrinter ORDER BY UserName ";
            return strSQL;
        }
        #endregion
        #region Fields
        private string Fields
        {
            get
            {
                return @"UserName, ReportType,CopyType,PrinterName,MenuID";
            }
        }
        #endregion
        #region	SelectDataByRecID
        public MPrinterDEL  SelectDataByRecID(DBAccess dBAccess, string strRecId)
        {
            MPrinterDEL mPrinterDEL = new MPrinterDEL();
            string strSql = string.Empty;
            strSql = "SELECT " + Fields + ",RecId,RecStamp FROM mPrinter ";
            if (strRecId != "" && int.Parse(strRecId) >= 0)
            {
                strSql += " WHERE RecId=" + strRecId;
            }
            dBAccess.GetDataSet(strSql, MPrinterDEL.TABLENAME_MPRINTER, mPrinterDEL);
            return mPrinterDEL;
        }
        #endregion
        #region Select for look up
        public string SelectMPrinterForLookUp()
        {
            return "SELECT UserName, ReportType,CopyType,PrinterName,RecID From mPrinter ORDER BY UserName ";
        }
        #endregion
        #region Select by Key
        public MPrinterDEL SelectMPrinterByKey(DBAccess dBAccess, int iRecID)
        {
            MPrinterDEL mPrinterDEL = new MPrinterDEL();
            string strSql = string.Empty;
            object[] oValues;
            strSql = @"SELECT RecID, UserName, ReportType,CopyType,PrinterName From mPrinter WHERE RecID={0}";
            oValues = new object[1];
            oValues[0] = iRecID;
            strSql = string.Format(strSql, oValues);
            dBAccess.GetDataSet(strSql, MPrinterDEL.TABLENAME_MPRINTER, mPrinterDEL);
            return mPrinterDEL;
        }
        #endregion  
        #region Insert table by DataRow
        public void InsertMPrinter(DBAccess dBAccess, MPrinterDEL mPrinterDEL)
        {
            string strSql = string.Empty;
            DataRow dr = mPrinterDEL.Tables[0].Rows[0];
            strSql = BaseFunctions.GenerateSqlForDataAccess(Fields, MPrinterDEL.TABLENAME_MPRINTER, dr, FormStatus.AddNew);
            dr[MPrinterDEL.RECID] = dBAccess.GetObjectValue(strSql);
        }
        #endregion
        #region Update MPrinter
        public void UpdateMPrinter(DBAccess dBAccess, MPrinterDEL mPrinterDEL)
        {
            string strSql = string.Empty;
            DataRow dr = mPrinterDEL.Tables[0].Rows[0];
            strSql = BaseFunctions.GenerateSqlForDataAccess(Fields, MPrinterDEL.TABLENAME_MPRINTER, dr, FormStatus.Update);
            dr[MPrinterDEL.RECSTAMP] = dBAccess.GetObjectValue(strSql);
        }
        #endregion
        #region Delete table by Key
        public void DeleteMPrinter(DBAccess dBAccess, int iRecID)
        {
            string strSql = string.Empty;  
            strSql = @"DELETE FROM mPrinter WHERE RecID=" + iRecID;
            dBAccess.ExecuteSql(strSql);
        }
        #endregion
    }
}
